package com.mornstar.secure.service;

import com.mornstar.econvent.hrm.entity.HrmResourceManager;
import com.mornstar.econvent.hrm.service.IHrmResourceManagerService;
import com.mornstar.econvent.hrm.service.IHrmResourceService;
import com.mornstar.log.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 用户验证处理
 *
 * @author xiekun
 */
@Slf4j
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private IHrmResourceManagerService resourceManagerService ;

    @Autowired
    private IHrmResourceService hrmResourceService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        HrmResourceManager hrmResourceManager = resourceManagerService.getById("") ;
        if (hrmResourceManager == null) {
            log.info("登录用户：{} 不存在.", username);
            throw new ServiceException("user.not.exists");
        }

        // passwordService.validate(user);
        return null ; //createLoginUser(user);
    }

//    public UserDetails createLoginUser(SysUser user) {
//        return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user));
//    }
}
